const BaseHandler     = require('../base-handler');
const HTTP_VERBS      = require('../../../constants').HTTP_VERBS;

class PlatformAuthorizeHandler extends BaseHandler {

    get pattern() {
        return "/wechat/platform/authorize";
    }

    doGET(request, response) {
        //?auth_code=queryauthcode@@@7kFOgzQamfAwNbpaRFs_UzHQUOvm3ENBskgV811bMh4F6ZW9dy6q8y8tiYmPShKi0YHlI3F9fqtjWpxCqiZPyQ&expires_in=3600
        this.Controller.handleWeChatPlatformAuthorization(request.query, request.session.user.id, (result) => {
            if (result && result.success) {
                result.data = {
                    social_id: result.data.app_id,
                    type: 'wechat'
                };
            }
            response.render('console/authorize', result);
        });
    }

    setup() {
        this.registerVerb(HTTP_VERBS.GET, this.doGET);
    }
}

module.exports = PlatformAuthorizeHandler;